package com.ezhuan.common.util;

import java.util.HashMap;
import java.util.Hashtable;
import java.util.Map;
import java.util.ResourceBundle;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.ezhuan.system.service.ISystemService;
import com.ezhuan.system.service.impl.SystemServiceImplay;
import com.ezhuan.task.service.ITaskService;
import com.ezhuan.task.service.impl.TaskServiceImpl;
import com.ezhuan.users.service.IIntegralService;
import com.ezhuan.users.service.IUsersService;
import com.ezhuan.users.service.impl.IntegralServiceImpl;
import com.ezhuan.users.service.impl.UsersServiceImpl;

/**
 * 常量工具类
 * 
 * @author wangshSxt
 *
 */
public class ConstatFinalUtil
{
	/* 记录日志对象 */
	public static Logger LOGGER = LogManager.getLogger();
	/* 加载配置文件 */
	public static ResourceBundle BUNDLE = ResourceBundle.getBundle("system");
	/* 资源文件 */
	public static JSONObject RESOURCE_JSON = new JSONObject() ;
	/* 信息提示对象 */
	public static JSONObject INFO_JSON = new JSONObject();
	/* 配置提示对象 */
	public static JSONObject CONFIG_JSON = new JSONObject();
	/* 多线程工具类 */
	public static Map<String, Map> THREAD_MAP = new Hashtable<String,Map>();
	/* 分隔符 */
	public static String SPLIT_STR = " ";
	/* Service的Bean */
	public static Map<String,Object> BEANMAP = new HashMap<String, Object>();
	
	/* 初始化 */
	/* 静态代码块:初始化一次 */
	static
	{
		/* 读取JSON配置文件 */
		FileUtil fileUtil = new FileUtil();
		String resourceStr = "" ; 
		try
		{
			resourceStr = fileUtil.readFile(ConstatFinalUtil.class.getClassLoader().getResourceAsStream("resourceInfo.json"));
			RESOURCE_JSON = (JSONObject) JSON.parse(resourceStr);
			
			/* 获取json配置文件中info信息 */
			INFO_JSON = RESOURCE_JSON.getJSONObject("info");
			/* 获取json配置文件中info信息 */
			CONFIG_JSON = RESOURCE_JSON.getJSONObject("config");
			ConstatFinalUtil.LOGGER.info("JSON配置文件");
		} catch (Exception e)
		{
			ConstatFinalUtil.LOGGER.info("JSON配置文件转换报错了,字符串:{}",resourceStr,e);
		}
		
		/* 初始化Bean */
		ITaskService taskService = new TaskServiceImpl();
		ISystemService systemService = new SystemServiceImplay() ; 
		IUsersService usersService = new UsersServiceImpl() ; 
		IIntegralService integralService = new IntegralServiceImpl() ; 
		
		ConstatFinalUtil.BEANMAP.put("taskService", taskService);
		ConstatFinalUtil.BEANMAP.put("systemService", systemService);
		ConstatFinalUtil.BEANMAP.put("usersService", usersService);
		ConstatFinalUtil.BEANMAP.put("integralService", integralService);
	}

	public static void main(String[] args)
	{
		ConstatFinalUtil.LOGGER.info("----");
	}
}
